<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" style="width: 1000px; margin: 0 auto"   :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="8">
            <a-form-model-item label="名字" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name">
              <a-input v-model="model.name" placeholder="请输入名字"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="省市" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="department">
             <j-area-linkage type="cascader" v-model="model.department" placeholder="请输入省市区"  />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="人员" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="people">
              <j-select-user-by-dep v-model="model.people" :multi="true" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="班级" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="classes">
              <j-dict-select-tag type="list" v-model="model.classes" dictCode="mwx_class,class_name,class_name" placeholder="请选择班级" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="邮件" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="email">
              <a-input v-model="model.email" placeholder="请输入电子邮件"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="性别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sex">
              <j-dict-select-tag type="radio" v-model="model.sex" dictCode="sex" placeholder="请选择性别" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="生日" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="birthday">
              <j-date placeholder="请选择生日" v-model="model.birthday"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="体重" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bodyWeight">
              <a-input-number v-model="model.bodyWeight" placeholder="请输入体重" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="status">
              <j-switch v-model="model.status"  ></j-switch>
            </a-form-model-item>
          </a-col>

          <a-col :span="12">
            <a-button type="primary" @click="loadClassData">向后端发送数据提取请求</a-button>
          </a-col>

          <a-col :span="24">
<!--            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" style="width: 800px;margin: auto" prop="notes">-->
<!--            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="notes">-->
<!--              <a-textarea v-model="model.notes" rows="4" placeholder="请输入备注" />-->
<!--            </a-form-model-item>-->
            <a-textarea v-model="model.notes" style="width: 900px;margin-left: 45px" rows="4" placeholder="请输入备注" />
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="照片" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="photo">
              <j-image-upload isMultiple  v-model="model.photo" ></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="档案文件" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="files">
              <j-upload v-model="model.files"  biz="F:/opt/upFiles/archivalFiles" ></j-upload>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'MwxZjTestForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        //校验规则
        validatorRules: {
          "name":{ required:true, message:'请填写姓名'},
          "email":{ required:true, message:'请填写email'}
        },
        url: {
          add: "/mwx/mwxZjTest/add",
          edit: "/mwx/mwxZjTest/edit",
          queryById: "/mwx/mwxZjTest/queryById",
          classList:"/mwx/mwxClass/list"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      loadClassData(){
        //向后台发送get请求
        // getAction("/mwx/mwxClass/list",{name: this.model.name})
        //   .then(res=>{
        //   console.log(res.result.records[3].classTeacher)
        // })
        getAction(this.url.classList)
          .then(res=>{
            // console.log(res)
            console.log(res.success)
            if(res.success){
              let items = res.result.records
              let row = 0

              //常用
              //js对数组操作
              items.forEach(item=>{
                console.log(row,item)
                console.log(item.classTeacher)
              })
            }
          })
      },
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }

        })
      },
    }
  }
</script>